<template>
	<view class="page">
		<template v-if="isLogin">
			<!-- <view class="h90">
				<view class="fix-wrap">
					<view class="search-bar">
						<view class="search-form">
							<view class="icon sc-icon iconfont icon-sousuo"></view>
							<input type="text" v-model="params.keyword" class="sc-inp" placeholder="输入关键词搜索" @input="search">
							<view v-if="params.keyword" class="icon clear-btn iconfont icon-shanchu" @click="clearKeyword"></view>
						</view>
					</view>
					<view class="h45">
						<view class="filter-bar"> 
							<picker class="item" mode="date" @change="changeDate" data-type="start"> 						
								<view class="name">{{params.beginTime||'开始日期'}}</view>
								<view class="iconfont icon-jiantou_liebiaozhankai_o f-s60"></view>
							</picker>
							<picker class="item" mode="date" @change="changeDate" data-type="end">								
								<view class="name">{{params.endTime||'结束日期'}}</view>
								<view class="iconfont icon-jiantou_liebiaozhankai_o f-s60"></view>
							</picker>
						</view> 
					</view> 
				</view>
			</view> -->
			<view class="body">
				<template v-if="loadingState.default">
					<loading :loadingState="loadingState"></loading>
				</template> 
				<template v-else>
					<template v-if="list.length>0">
						<view class="list-wrap">
							<navigator :url="'/package_yunpeixun/dataDetail/dataDetail?id='+item.id" open-type="navigate" hover-class="none" class="item" v-for="(item,index) in list" :key="index">
								<view class="pic">
									<image :src="img_path+item.file_path" mode="widthFix"></image>
								</view>
								<view class="info">
									<view class="name split-line">{{item.px_name}}</view>
									<view class="time">{{item.px_date}}</view>
								</view>								
							</navigator>
						</view> 
						<loading :loadingState="loadingState"></loading>
					</template>
					<template v-else>
					 	<empty msg="暂无相关数据"></empty>
					</template>
				</template>
			</view> 
		</template>
	</view>
</template>

<script>
	import loading from '@/components/loading-more.vue'
	import empty from '@/components/empty.vue'
	import {admin_img_path} from '@/config.js'
	export default {
		name: 'demo',
		data() {
			return {
				isLogin: false,
				userInfo: uni.getStorageSync('userInfo'), 
				list:[],
				total:0,
				loadingState:{
					default:false,
					loading:false,
					completed:false
				}, 
				params: { 
					page:1,
					beginTime: '',
					endTime: '',
					keyword:'',
					limit:20
				}, 
				img_path:admin_img_path
			}
		},
		onShow() {

		},
		async onLoad(params) {  
			let s_params=JSON.parse(params.params);
			this.params.beginTime=s_params.beginTime;
			this.params.endTime=s_params.endTime;
			this.params.keyword=s_params.keyword; 
			this.isLogin = await this.$loginState('check');
			if(this.isLogin){
				this.getData(); 
			}
		},
		onReachBottom(){
			if(this.loadingState.completed){ 
				this.params.page=1;
				return false
			}else{
				if(this.list.length<this.total&&this.list.length>0){
					this.params.page++; 
					this.getData();
				} 
			}	 
		},
		methods: {
			 
			
			// 查询
			getData:async function () {  
				let res=await this.$api.ypx_api.ypxDataList({
					keyword:this.params.keyword,
					beginTime: this.params.beginTime,
					endTime: this.params.endTime,
					page:this.params.page,
					limit:this.params.limit,
					province: this.params.province,
					city: this.params.city,
					district: this.params.district,
					town: this.params.town,
					village: this.params.village,
					is_app:1
				}) 
				this.loadingState.default=true;
				console.log(res,{
					keyword:this.params.keyword,
					beginTime: this.params.beginTime,
					endTime: this.params.endTime,
					page:this.params.page,
					limit:this.params.limit,
					province: this.params.province,
					city: this.params.city,
					district: this.params.district,
					town: this.params.town,
					village: this.params.village,
					is_app:1
				})
				if(res.data.ret==0){ 
					this.loadingState.default=false;
					this.loadingState.loading=true;
					this.total=res.data.data.count;
					this.list=this.list.concat(res.data.data.list);
					if(this.list.length==this.total){ 
						this.loadingState.loading=false;
						this.loadingState.completed=true;
					}
				}else{
					this.loadingState.default=false; 
				}
			},

		},
		computed: {

		},
		components: {
			loading,
			empty
		}
	}
</script>

<style lang="less">
	.list-wrap{
		margin-top: 20rpx;
		background: #fff;
		.item{
			display: flex; 
			padding:20rpx 20rpx 20rpx 0;
			margin-left: 20rpx;
			border-bottom: 1rpx solid #eee;
			font-size: 30rpx;
			.pic{
				width: 30%;
				height: 150rpx;
				margin-right: 20rpx;
				overflow: hidden;
			}
			.info{
				width: 70%;
				.name{
					font-size: 30rpx;
				}
				.time{
					color: #999;
					font-size: 28rpx;
				}
			}
			
		}
	}
</style>
